#include <SDL/SDL.h>
#include <stdlib.h>

unsigned int getpixelki(SDL_Surface *s, int x, int y)
{
  return ((unsigned int*)s->pixels)[y*(s->pitch/sizeof(unsigned int))+x];
}

void ki(SDL_Rect ball[],SDL_Rect obj[],SDL_Surface *screen,int *level,int *autoaim,int *mode)
{  
  if(((obj[1].x-ball[0].x)<(screen->w/4))&&(*mode==1))
    {
      if((obj[1].y+(obj[1].h/2))<ball[0].y)
	{
	  if ((getpixelki(screen,obj[1].x,obj[1].y+obj[1].h+10))==16777215) 
	    {
	      SDL_FillRect(screen,&obj[1],SDL_MapRGB(screen->format,255,255,255));
	      obj[1].y+=((screen->h/120)+(*level*(screen->h/330)));
	    }
	}
      if((obj[1].y+(obj[1].h/2))>ball[0].y)
	{
	  if ((getpixelki(screen,obj[1].x,obj[1].y-10))==16777215) 
	    {
	      SDL_FillRect(screen,&obj[1],SDL_MapRGB(screen->format,255,255,255));
	      obj[1].y-=((screen->h/120)+(*level*(screen->h/330)));
	    }
	}
    }
  
  
  if((*autoaim==1)&&((ball[0].x-obj[0].x)<(screen->w/2)))
    {
      if(obj[0].y<ball[0].y)
	{
	  if ((getpixelki(screen,obj[0].x,obj[0].y+obj[0].h+10))==16777215) 
	    {
	      SDL_FillRect(screen,&obj[0],SDL_MapRGB(screen->format,255,255,255));
	      obj[0].y+=(screen->w/100);
	    }
	}
      if(obj[0].y>ball[0].y)
	{
	  if ((getpixelki(screen,obj[0].x,obj[0].y-10))==16777215) 
	    {
	      SDL_FillRect(screen,&obj[0],SDL_MapRGB(screen->format,255,255,255));
	      obj[0].y-=(screen->w/100);
	    }
	}
    } 
}
